﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WastedMechanics
{
    public class CharacterAnimBlender : AnimBlender
    {
        public CharacterAnimBlender(Character character)
            : base(character)
        {
        }

        protected override void LinkAnimations()
        {            
            LinkedStates.Add(new List<AnimStatePart>());
            LinkedStates[0].Add(AnimStates["WalkLegs"]);
            LinkedStates[0].Add(AnimStates["WalkTorso"]);
            LinkedStates[0].Add(AnimStates["WalkM1HTorso"]);
            LinkedStates.Add(new List<AnimStatePart>());
            LinkedStates[1].Add(AnimStates["RunLegs"]);
            LinkedStates[1].Add(AnimStates["RunTorso"]);
            LinkedStates[1].Add(AnimStates["RunM1HTorso"]);
        }

        protected override void CreateAnimStates()
        {
            AddAnimState(Character.BodyEntity, "IdleLegs");
            Groups["Legs"].AddState(AnimStates["IdleLegs"]);

            AddAnimState(Character.BodyEntity, "IdleTorso");
            Groups["Torso"].AddState(AnimStates["IdleTorso"]);

            AddAnimState(Character.BodyEntity, "WalkLegs");
            Groups["Legs"].AddState(AnimStates["WalkLegs"]);

            AddAnimState(Character.BodyEntity, "WalkTorso");
            Groups["Torso"].AddState(AnimStates["WalkTorso"]);

            AddAnimState(Character.BodyEntity, "RunLegs");
            Groups["Legs"].AddState(AnimStates["RunLegs"]);

            AddAnimState(Character.BodyEntity, "RunTorso");
            Groups["Torso"].AddState(AnimStates["RunTorso"]);

            AddAnimState(Character.BodyEntity, "PickItemDown", false);
            Groups["Torso"].AddState(AnimStates["PickItemDown"]);
            Groups["Legs"].AddState(AnimStates["PickItemDown"]);

            AddAnimState(Character.BodyEntity, "PickItemFront", false);
            Groups["Torso"].AddState(AnimStates["PickItemFront"]);
            Groups["Legs"].AddState(AnimStates["PickItemFront"]);

            AddAnimState(Character.BodyEntity, "IdleUnarmedLegs");
            Groups["Legs"].AddState(AnimStates["IdleUnarmedLegs"]);

            AddAnimState(Character.BodyEntity, "IdleUnarmedTorso");
            Groups["Torso"].AddState(AnimStates["IdleUnarmedTorso"]);

            AddAnimState(Character.BodyEntity, "Falling");
            Groups["Torso"].AddState(AnimStates["Falling"]);
            Groups["Legs"].AddState(AnimStates["Falling"]);

            AddAnimState(Character.BodyEntity, "Punch", false);
            Groups["Torso"].AddState(AnimStates["Punch"]);
            Groups["Legs"].AddState(AnimStates["Punch"]);

            AddAnimState(Character.BodyEntity, "Ouch", false);
            Groups["Torso"].AddState(AnimStates["Ouch"]);
            Groups["Legs"].AddState(AnimStates["Ouch"]);

            AddAnimState(Character.BodyEntity, "ClimbHigh", false);
            Groups["Torso"].AddState(AnimStates["ClimbHigh"]);
            Groups["Legs"].AddState(AnimStates["ClimbHigh"]);

            AddAnimState(Character.BodyEntity, "JumpStand", false);
            Groups["Torso"].AddState(AnimStates["JumpStand"]);
            Groups["Legs"].AddState(AnimStates["JumpStand"]);

            AddAnimState(Character.BodyEntity, "JumpLand", false);
            Groups["Torso"].AddState(AnimStates["JumpLand"]);
            Groups["Legs"].AddState(AnimStates["JumpLand"]);

            AddAnimState(Character.BodyEntity, "JumpClimb", false);
            Groups["Torso"].AddState(AnimStates["JumpClimb"]);
            Groups["Legs"].AddState(AnimStates["JumpClimb"]);

            AddAnimState(Character.BodyEntity, "JumpClimbUp");
            Groups["Torso"].AddState(AnimStates["JumpClimbUp"]);
            Groups["Legs"].AddState(AnimStates["JumpClimbUp"]);

            AddAnimState(Character.BodyEntity, "IdlePistolLegs");
            Groups["Legs"].AddState(AnimStates["IdlePistolLegs"]);

            AddAnimState(Character.BodyEntity, "TakePistolTorso", false);
            Groups["Torso"].AddState(AnimStates["TakePistolTorso"]);

            AddAnimState(Character.BodyEntity, "HidePistolTorso", false);
            Groups["Torso"].AddState(AnimStates["HidePistolTorso"]);

            AddAnimState(Character.BodyEntity, "AimPistolTorso");
            Groups["Torso"].AddState(AnimStates["AimPistolTorso"]);

            AddAnimState(Character.BodyEntity, "PistolShootTorso", false);
            Groups["Torso"].AddState(AnimStates["PistolShootTorso"]);

            AddAnimState(Character.BodyEntity, "RunM1HTorso");
            Groups["Torso"].AddState(AnimStates["RunM1HTorso"]);            

            AddAnimState(Character.BodyEntity, "WalkM1HTorso");
            Groups["Torso"].AddState(AnimStates["WalkM1HTorso"]);            

            AddAnimState(Character.BodyEntity, "IdleM1HTorso");
            Groups["Torso"].AddState(AnimStates["IdleM1HTorso"]);            

            AddAnimState(Character.BodyEntity, "IdleM1HLegs");
            Groups["Legs"].AddState(AnimStates["IdleM1HLegs"]);

            AddAnimState(Character.BodyEntity, "M1HHit1", false);
            Groups["Torso"].AddState(AnimStates["M1HHit1"]);
            Groups["Legs"].AddState(AnimStates["M1HHit1"]);

            AddAnimState(Character.BodyEntity, "Die", false);
            Groups["Torso"].AddState(AnimStates["Die"]);
            Groups["Legs"].AddState(AnimStates["Die"]);

            AddAnimState(Character.BodyEntity, "Dead", false);
            Groups["Torso"].AddState(AnimStates["Dead"]);
            Groups["Legs"].AddState(AnimStates["Dead"]);                        
        }

        protected override void ComposeAnimations()
        {            
            Anims["IdleNothing"] = new AnimComposition("IdleNothing");
            Anims["IdleNothing"].Add(AnimStates["IdleLegs"]);
            Anims["IdleNothing"].Add(AnimStates["IdleTorso"]);

            Anims["WalkNothing"] = new AnimComposition("WalkNothing");
            Anims["WalkNothing"].Add(AnimStates["WalkLegs"]);
            Anims["WalkNothing"].Add(AnimStates["WalkTorso"]);

            Anims["RunNothing"] = new AnimComposition("RunNothing");
            Anims["RunNothing"].Add(AnimStates["RunLegs"]);
            Anims["RunNothing"].Add(AnimStates["RunTorso"]);

            Anims["PickItemDown"] = new AnimComposition("PickItemDown");
            Anims["PickItemDown"].Add(AnimStates["PickItemDown"]);

            Anims["PickItemFront"] = new AnimComposition("PickItemFront");
            Anims["PickItemFront"].Add(AnimStates["PickItemFront"]);

            Anims["IdleUnarmed"] = new AnimComposition("IdleUnarmed");
            Anims["IdleUnarmed"].Add(AnimStates["IdleUnarmedLegs"]);
            Anims["IdleUnarmed"].Add(AnimStates["IdleUnarmedTorso"]);

            Anims["WalkUnarmed"] = new AnimComposition("WalkUnarmed");
            Anims["WalkUnarmed"].Add(AnimStates["WalkLegs"]);
            Anims["WalkUnarmed"].Add(AnimStates["IdleUnarmedTorso"]);

            Anims["RunUnarmed"] = new AnimComposition("RunUnarmed");
            Anims["RunUnarmed"].Add(AnimStates["RunLegs"]);
            Anims["RunUnarmed"].Add(AnimStates["IdleUnarmedTorso"]);

            Anims["Punch"] = new AnimComposition("Punch");
            Anims["Punch"].Add(AnimStates["Punch"]);

            Anims["Ouch"] = new AnimComposition("Ouch");
            Anims["Ouch"].Add(AnimStates["Ouch"]);

            Anims["JumpStand"] = new AnimComposition("JumpStand");
            Anims["JumpStand"].Add(AnimStates["JumpStand"]);

            Anims["Falling"] = new AnimComposition("Falling");
            Anims["Falling"].Add(AnimStates["Falling"]);

            Anims["JumpLand"] = new AnimComposition("JumpLand");
            Anims["JumpLand"].Add(AnimStates["JumpLand"]);

            Anims["ClimbHigh"] = new AnimComposition("ClimbHigh");
            Anims["ClimbHigh"].Add(AnimStates["ClimbHigh"]);

            Anims["JumpClimb"] = new AnimComposition("JumpClimb");
            Anims["JumpClimb"].Add(AnimStates["JumpClimb"]);

            Anims["JumpClimbUp"] = new AnimComposition("JumpClimbUp");
            Anims["JumpClimbUp"].Add(AnimStates["JumpClimbUp"]);

            Anims["TakePistolIdle"] = new AnimComposition("TakePistolIdle");
            Anims["TakePistolIdle"].Add(AnimStates["IdleLegs"]);
            Anims["TakePistolIdle"].Add(AnimStates["TakePistolTorso"]);

            Anims["HidePistolIdle"] = new AnimComposition("HidePistolIdle");
            Anims["HidePistolIdle"].Add(AnimStates["IdleLegs"]);
            Anims["HidePistolIdle"].Add(AnimStates["HidePistolTorso"]);

            Anims["IdlePistol"] = new AnimComposition("IdlePistol");
            Anims["IdlePistol"].Add(AnimStates["IdlePistolLegs"]);
            Anims["IdlePistol"].Add(AnimStates["IdleTorso"]);

            Anims["IdlePistolAim"] = new AnimComposition("IdlePistolAim");
            Anims["IdlePistolAim"].Add(AnimStates["IdlePistolLegs"]);
            Anims["IdlePistolAim"].Add(AnimStates["AimPistolTorso"]);

            Anims["IdlePistolShoot"] = new AnimComposition("IdlePistolShoot");
            Anims["IdlePistolShoot"].Add(AnimStates["IdlePistolLegs"]);
            Anims["IdlePistolShoot"].Add(AnimStates["PistolShootTorso"]);

            Anims["WalkPistol"] = new AnimComposition("WalkPistol");
            Anims["WalkPistol"].Add(AnimStates["WalkLegs"]);
            Anims["WalkPistol"].Add(AnimStates["WalkTorso"]);

            Anims["WalkPistolAim"] = new AnimComposition("WalkPistolAim");
            Anims["WalkPistolAim"].Add(AnimStates["WalkLegs"]);
            Anims["WalkPistolAim"].Add(AnimStates["AimPistolTorso"]);

            Anims["WalkPistolShoot"] = new AnimComposition("WalkPistolShoot");
            Anims["WalkPistolShoot"].Add(AnimStates["WalkLegs"]);
            Anims["WalkPistolShoot"].Add(AnimStates["PistolShootTorso"]);

            Anims["RunPistol"] = new AnimComposition("RunPistol");
            Anims["RunPistol"].Add(AnimStates["RunLegs"]);
            Anims["RunPistol"].Add(AnimStates["RunTorso"]);

            Anims["RunPistolAim"] = new AnimComposition("RunPistolAim");
            Anims["RunPistolAim"].Add(AnimStates["RunLegs"]);
            Anims["RunPistolAim"].Add(AnimStates["AimPistolTorso"]);

            Anims["RunPistolShoot"] = new AnimComposition("RunPistolShoot");
            Anims["RunPistolShoot"].Add(AnimStates["RunLegs"]);
            Anims["RunPistolShoot"].Add(AnimStates["PistolShootTorso"]);

            Anims["WalkM1H"] = new AnimComposition("WalkM1H");
            Anims["WalkM1H"].Add(AnimStates["WalkLegs"]);
            Anims["WalkM1H"].Add(AnimStates["WalkM1HTorso"]);

            Anims["RunM1H"] = new AnimComposition("RunM1H");
            Anims["RunM1H"].Add(AnimStates["RunLegs"]);
            Anims["RunM1H"].Add(AnimStates["RunM1HTorso"]);

            Anims["IdleM1H"] = new AnimComposition("IdleM1H");
            Anims["IdleM1H"].Add(AnimStates["IdleM1HLegs"]);
            Anims["IdleM1H"].Add(AnimStates["IdleM1HTorso"]);

            Anims["M1HHit1"] = new AnimComposition("M1HHit1");
            Anims["M1HHit1"].Add(AnimStates["M1HHit1"]);

            Anims["Die"] = new AnimComposition("Die");
            Anims["Die"].Add(AnimStates["Die"]);

            Anims["Dead"] = new AnimComposition("Dead");
            Anims["Dead"].Add(AnimStates["Dead"]);
        }

        protected override void CreateGroups()
        {            
            Groups["Torso"] = new AnimGroup(Character);
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Spine1"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Spine2"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Spine3"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Neck"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("HeadFront"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Head"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Mouth.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Mouth.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Jaw"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm1.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm2.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm3.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm4.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand1.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand2.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand3.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand4.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb1.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb2.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb3.L"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm1.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm2.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm3.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Arm4.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand1.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand2.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand3.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Hand4.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb1.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb2.R"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("Thumb3.R"));    
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("PistolHand"));
            Groups["Torso"].AddBone(Character.BodyEntity.Skeleton.GetBone("PistolHandHandle"));

            Groups["Legs"] = new AnimGroup(Character);
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Main"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg1.L"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg2.L"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg3.L"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Foot.L"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg1.R"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg2.R"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Leg3.R"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("Foot.R"));            
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("PistolPocketHandle"));
            Groups["Legs"].AddBone(Character.BodyEntity.Skeleton.GetBone("PistolPocket"));
        }
    }
}
